package com.uzai.console.service.user.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uzai.common.entity.User;
import com.uzai.common.entity.WechatUser;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.common.exception.BusinessException;
import com.uzai.common.result.ResponseCode;
import com.uzai.common.utils.EsIndexName;
import com.uzai.console.common.utils.DateUtil;
import com.uzai.console.common.utils.Tools;
import com.uzai.console.constant.CacheKey;
import com.uzai.console.constant.ES.ESResult;
import com.uzai.console.constant.ES.ElasticsearchUtil;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvIdDto;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvIdListDto;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvInfoDto;
import com.uzai.console.dto.user.wechatblacklist.WechatBlacklistPrvQuery;
import com.uzai.console.entity.Device;
import com.uzai.console.entity.es.WechatBlacklistPrv;
import com.uzai.console.entity.es.WechatBlacklistPub;
import com.uzai.console.mapper.WechatUserMapper;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.user.UserOperatorService;
import com.uzai.console.service.user.UserService;
import com.uzai.console.service.user.WechatBlacklistPrvService;
import com.uzai.console.vo.user.wechatblacklist.WechatBlacklistPrvInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author liuqi
 * @date 2021年08月23日 20:25
 */
@Service
public class WechatBlacklistPrvServiceImpl implements WechatBlacklistPrvService {

    Logger logger = LoggerFactory.getLogger(WechatBlacklistPrvServiceImpl.class);

    @Autowired
    private DeviceService deviceService;
    @Autowired
    private UserService userService;
    @Autowired
    private WechatUserMapper wechatUserMapper;
    @Autowired
    private ElasticsearchUtil elasticsearchUtil;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private UserOperatorService userOperatorService;


    /**
     * 查询私有黑名单列表
     *
     * @param wechatBlacklistPrvQuery
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    public Page<WechatBlacklistPrvInfoVo> findWechatBlacklistPrvList(WechatBlacklistPrvQuery wechatBlacklistPrvQuery) {
        //新建返回到页面的LIST对象
        List<WechatBlacklistPrvInfoVo> wechatBlacklistPrvInfoVoList = new ArrayList<>();

        //执行分页查询对象
        Page<WechatBlacklistPrvInfoVo> page = new Page<>();
        wechatBlacklistPrvQuery.convert(page);

        //ES查询
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();

        //运营商ID
        boolQuery.must(QueryBuilders.termQuery("merId", Tools.getLong(wechatBlacklistPrvQuery.getMerId())));

        //黑名单类型(0常规 1刷单 2同行 3店淘 4敲诈 5撸狗)
        if (wechatBlacklistPrvQuery.getType() != null) {
            boolQuery.must(QueryBuilders.termQuery("type", wechatBlacklistPrvQuery.getType()));
        }

        //微信id
        //验证是否为会员ID，如果是，则用会员id来查询微信id，如果不是，则用微信id来查询
        if (StringUtils.isNotBlank(wechatBlacklistPrvQuery.getWxid())) {
            boolQuery.must(QueryBuilders.termQuery("wxid", wechatBlacklistPrvQuery.getWxid()));
        }

        //微信id
        //验证是否为会员ID，如果是，则用会员id来查询微信id，如果不是，则用微信id来查询
        if (wechatBlacklistPrvQuery.getUserId() != null) {
            User user = userService.findUserInfo(wechatBlacklistPrvQuery.getUserId(), null, wechatBlacklistPrvQuery.getMerId());
            if (user != null) {
                boolQuery.must(QueryBuilders.termQuery("wxid", user.getBizUserId()));
            }
        }

        //设备类型
        if (StringUtils.isNotBlank(wechatBlacklistPrvQuery.getDeviceType())) {
            boolQuery.must(QueryBuilders.termQuery("deviceType", wechatBlacklistPrvQuery.getDeviceType()));
        }

        //高亮字段
        String highlightField = null;

        //微信昵称
        if (StringUtils.isNotBlank(wechatBlacklistPrvQuery.getNickName())) {
            boolQuery.must(QueryBuilders.matchQuery("nickName", wechatBlacklistPrvQuery.getNickName()));
            highlightField = "nickName";
        }


        searchSourceBuilder.query(boolQuery);

        //排序
        searchSourceBuilder.sort("createTime", SortOrder.DESC);

        try {
            ESResult esResult = elasticsearchUtil.searchListData(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, searchSourceBuilder, wechatBlacklistPrvQuery.getSize(), wechatBlacklistPrvQuery.getFromIndex(), null, null, highlightField, wechatBlacklistPrvQuery.getMerId());
            page.setTotal(esResult.getTotalHits());
            List<Map<String, Object>> dataList = esResult.getDataList();
            if (dataList != null && dataList.size() > 0) {
                for (Map<String, Object> dataMp : dataList) {
                    WechatBlacklistPrv wechatBlacklistPrv = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(dataMp)), WechatBlacklistPrv.class);
                    if (wechatBlacklistPrv != null) {
                        WechatBlacklistPrvInfoVo wechatBlacklistPrvInfoVo = new WechatBlacklistPrvInfoVo();
                        BeanUtils.copyProperties(wechatBlacklistPrv, wechatBlacklistPrvInfoVo);
                        if (wechatBlacklistPrv.getDeviceUniqueId() != null) {
                            Device device = deviceService.findDeviceInfoByDeviceUniqueId(wechatBlacklistPrv.getDeviceUniqueId(), wechatBlacklistPrv.getDeviceType(), wechatBlacklistPrv.getMerId());
                            if (device != null) {//机器人信息
                                wechatBlacklistPrvInfoVo.setDeviceId(device.getDeviceId());
                                wechatBlacklistPrvInfoVo.setDeviceName(device.getDeviceName());
                                wechatBlacklistPrvInfoVo.setDeviceRemark(device.getDeviceRemark());
                            }
                        }
                        //查询是否共享黑名单
                        String wxid = wechatBlacklistPrv.getWxid();
                        Map<String, Object> map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PUB, wxid, null);
                        if (map != null) {
                            wechatBlacklistPrvInfoVo.setShareStatus(1);  //已经共享
                        } else {
                            wechatBlacklistPrvInfoVo.setShareStatus(0);  //未共享
                        }

                        //封装会员id
                        User user = userService.findUserInfoByWxid(wechatBlacklistPrvQuery.getMerId(), wxid, wechatBlacklistPrv.getDeviceType());
                        if (user != null) {
                            wechatBlacklistPrvInfoVo.setUserId(user.getId());
                        }
                        wechatBlacklistPrvInfoVoList.add(wechatBlacklistPrvInfoVo);
                    }
                }
            }
        } catch (Exception e) {
            logger.error("查询ES出现异常,index=" + EsIndexName.UZAI_WECHAT_BLACKLIST_PRV);
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "查询失败");
        }

        //返回到页面分页对象
        page.setRecords(wechatBlacklistPrvInfoVoList);
        //将分页信息复制到返回到页面的分页MO当中
        return page;
    }

    /**
     * 添加私有黑名单
     *
     * @param wechatBlacklistPrvInfoDto
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    public void addWechatBlacklistPrv(WechatBlacklistPrvInfoDto wechatBlacklistPrvInfoDto) {

        if (wechatBlacklistPrvInfoDto.getType() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入黑名单类型");
        }

        if (StringUtils.isBlank(wechatBlacklistPrvInfoDto.getWxid())) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入微信id/会员id");
        }

        //会员信息
        User user = null;
        String wxid = wechatBlacklistPrvInfoDto.getWxid();
        boolean flag = StringUtils.isNumeric(wxid);
        if (flag) {
            Long id = Long.valueOf(wxid);
            user = userService.findUserInfo(id, null, wechatBlacklistPrvInfoDto.getMerId());

        } else {
            user = userService.findUserInfoByWxid(wechatBlacklistPrvInfoDto.getMerId(), wxid, null);
        }

        if (user == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "微信id/会员id在系统中不存在");
        }

        //id为merId_wxid
        wxid = user.getBizUserId();
        String id = wechatBlacklistPrvInfoDto.getMerId() + "_" + wxid;
        Map<String, Object> map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, id, null);
        if (map != null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该微信id已经在黑名单中");
        }

        WechatBlacklistPrv wechatBlacklistPrv = new WechatBlacklistPrv();
        wechatBlacklistPrv.setId(id);
        wechatBlacklistPrv.setMerId(wechatBlacklistPrvInfoDto.getMerId());
        wechatBlacklistPrv.setDeviceUniqueId(user.getDeviceUniqueId());
        wechatBlacklistPrv.setDeviceType(user.getDeviceType());
        wechatBlacklistPrv.setWxid(wxid);
        wechatBlacklistPrv.setNickName(user.getNickName());
        wechatBlacklistPrv.setHeadImg(user.getHeadImg());
        wechatBlacklistPrv.setType(wechatBlacklistPrvInfoDto.getType());
        wechatBlacklistPrv.setRemark(wechatBlacklistPrvInfoDto.getRemark());
        Integer now = DateUtil.getNowTime();
        wechatBlacklistPrv.setCreateTime(now);
        wechatBlacklistPrv.setUpdateTime(now);
        //增加黑名单
        elasticsearchUtil.addData(wechatBlacklistPrv, EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, id);

        //修改会员备注、通讯录备注、发送修改微信终端修改配置指令
        if (Tools.getInteger(wechatBlacklistPrvInfoDto.getUpdateRemarkFlag()).intValue() == 1 && StringUtils.isNotBlank(wechatBlacklistPrvInfoDto.getRemark())) {
            user.setRemark(wechatBlacklistPrvInfoDto.getRemark());
            userOperatorService.updateRemarkByUserAndContacts(user);
        }

        try {
            //延迟1秒
            Thread.sleep(1000);
        } catch (Exception e) {

        }
    }

    /**
     * 修改私有黑名单
     *
     * @param wechatBlacklistPrvInfoDto
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    @Transactional
    public void updateWechatBlacklistPrv(WechatBlacklistPrvInfoDto wechatBlacklistPrvInfoDto) {

        if (StringUtils.isBlank(wechatBlacklistPrvInfoDto.getId())) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        if (wechatBlacklistPrvInfoDto.getType() == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入黑名单类型");
        }

        if (StringUtils.isBlank(wechatBlacklistPrvInfoDto.getWxid())) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请输入微信id");
        }

        Map<String, Object> map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, wechatBlacklistPrvInfoDto.getId(), null);
        if (map == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该私有黑名单不存在");
        }

        WechatBlacklistPrv wechatBlacklistPrv = new WechatBlacklistPrv();
        BeanUtils.copyProperties(wechatBlacklistPrvInfoDto, wechatBlacklistPrv);
        Integer now = DateUtil.getNowTime();
        wechatBlacklistPrv.setUpdateTime(now);
        wechatBlacklistPrv.setType(wechatBlacklistPrvInfoDto.getType());
        wechatBlacklistPrv.setDeviceType(wechatBlacklistPrvInfoDto.getDeviceType());
        wechatBlacklistPrv.setWxid(wechatBlacklistPrvInfoDto.getWxid());
        //通过微信ID查询用户信息
        User user = userService.findUserInfoByWxid(wechatBlacklistPrvInfoDto.getMerId(), wechatBlacklistPrvInfoDto.getWxid(), wechatBlacklistPrvInfoDto.getDeviceType());
        if (user != null) {
            wechatBlacklistPrv.setDeviceUniqueId(user.getDeviceUniqueId());
            wechatBlacklistPrv.setNickName(user.getNickName());
            wechatBlacklistPrv.setHeadImg(user.getHeadImg());
        }

        elasticsearchUtil.updateDataById(wechatBlacklistPrv, EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, wechatBlacklistPrvInfoDto.getId());

        try {
            //延迟1秒
            Thread.sleep(1000);
        } catch (Exception e) {

        }
    }

    /**
     * 移除黑名单
     *
     * @param wechatBlacklistPrvIdDto
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    @Transactional
    public void deleteWechatBlacklistPrv(WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto) {

        if (StringUtils.isBlank(wechatBlacklistPrvIdDto.getId())) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        Map<String, Object> map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, wechatBlacklistPrvIdDto.getId(), null);
        WechatBlacklistPrv wechatBlacklistPrv = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(map)), WechatBlacklistPrv.class);
        if (wechatBlacklistPrv == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该私有黑名单不存在");
        }

        //删除私有黑名单
        elasticsearchUtil.deleteDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, wechatBlacklistPrvIdDto.getId());

        //判断是否自己共享了全网黑名单，如果是自己共享的，则同时删除全网黑名单
        Map<String, Object> pub_map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PUB, wechatBlacklistPrv.getWxid(), null);
        WechatBlacklistPub wechatBlacklistPub = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(pub_map)), WechatBlacklistPub.class);
        if (wechatBlacklistPub != null) {
            //判断是不是该运营商共享的全网黑名单
            if (wechatBlacklistPub.getMerId().longValue() == wechatBlacklistPrvIdDto.getMerId().longValue()) {
                elasticsearchUtil.deleteDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PUB, wechatBlacklistPrv.getWxid());
            }
        }
    }

    /**
     * 批量删除
     *
     * @param wechatBlacklistPrvIdListDto
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    public void batchDeleteWechatBlacklistPrv(WechatBlacklistPrvIdListDto wechatBlacklistPrvIdListDto) {

        List<String> idList = wechatBlacklistPrvIdListDto.getIdList();
        if (idList == null || idList.size() == 0) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "请选择输入批量删除记录");
        }

        //根据机器人列表查询需要增加限制时间
        if (idList.size() >= 100) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "批量删除总数量不能超过100个");
        }

        String val = (String) redisTemplate.opsForValue().get(String.format(CacheKey.BATCH_DELETE_USER_BLCKLIST_PRV, wechatBlacklistPrvIdListDto.getMerId()));
        if (StringUtils.isNotBlank(val)) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "2分钟只允许一次批量操作");
        }
        //往reids插入本次下载，允许5分钟下载一次，避免频繁提交
        redisTemplate.opsForValue().set(String.format(CacheKey.BATCH_DELETE_USER_BLCKLIST_PRV, wechatBlacklistPrvIdListDto.getMerId()), wechatBlacklistPrvIdListDto.getMerId() + "", 2, TimeUnit.MINUTES);

        for (String id : idList) {
            try {
                WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto = new WechatBlacklistPrvIdDto();
                wechatBlacklistPrvIdDto.setMerId(wechatBlacklistPrvIdListDto.getMerId());
                wechatBlacklistPrvIdDto.setId(id);
                deleteWechatBlacklistPrv(wechatBlacklistPrvIdDto);
            } catch (Exception e) {
                logger.error("批量删除删除会员黑名称出错。error={}", e.getMessage());
            }
        }
    }

    /**
     * 查询私有黑名单
     *
     * @param wechatBlacklistPrvIdDto
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    public WechatBlacklistPrvInfoVo findWechatBlacklistPrvInfo(WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto) {
        if (StringUtils.isBlank(wechatBlacklistPrvIdDto.getId())) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        Map<String, Object> map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, wechatBlacklistPrvIdDto.getId(), null);
        if (map == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该私有黑名单不存在");
        }

        WechatBlacklistPrv wechatBlacklistPrv = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(map)), WechatBlacklistPrv.class);
        WechatBlacklistPrvInfoVo wechatBlacklistPrvInfoVo = new WechatBlacklistPrvInfoVo();
        BeanUtils.copyProperties(wechatBlacklistPrv, wechatBlacklistPrvInfoVo);
        if (wechatBlacklistPrv.getDeviceUniqueId() != null) {
            Device device = deviceService.findDeviceInfoByDeviceUniqueId(wechatBlacklistPrv.getDeviceUniqueId(), wechatBlacklistPrv.getDeviceType(), wechatBlacklistPrv.getMerId());
            if (device != null) {//常规回复
                wechatBlacklistPrvInfoVo.setDeviceId(device.getDeviceId());
                wechatBlacklistPrvInfoVo.setDeviceName(device.getDeviceName());
                wechatBlacklistPrvInfoVo.setDeviceId(device.getDeviceRemark());
            }
        }
        return wechatBlacklistPrvInfoVo;
    }

    /**
     * 共享全网黑名单
     *
     * @param wechatBlacklistPrvIdDto
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    public void shareWechatBlacklistPub(WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto) {
        if (StringUtils.isBlank(wechatBlacklistPrvIdDto.getId())) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        Map<String, Object> map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, wechatBlacklistPrvIdDto.getId(), null);
        WechatBlacklistPrv wechatBlacklistPrv = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(map)), WechatBlacklistPrv.class);
        if (wechatBlacklistPrv == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该私有黑名单不存在");
        }

        //通过微信ID查询用户信息
        User user = userService.findUserInfoByWxid(wechatBlacklistPrvIdDto.getMerId(), wechatBlacklistPrv.getWxid(), DeviceTypeEnum.DT_PC_WECHAT.getKey());
        if (user == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该微信id不是自己会员，不能共享全网黑名单");
        }

        Map<String, Object> pub_map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PUB, wechatBlacklistPrv.getWxid(), null);
        WechatBlacklistPub wechatBlacklistPub = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(pub_map)), WechatBlacklistPub.class);
        if (wechatBlacklistPub != null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该微信id已经在共享黑名单里");
        }

        wechatBlacklistPub = new WechatBlacklistPub();
        BeanUtils.copyProperties(wechatBlacklistPrv, wechatBlacklistPub);
        Integer now = DateUtil.getNowTime();
        wechatBlacklistPub.setCreateTime(now);
        wechatBlacklistPub.setUpdateTime(now);
        wechatBlacklistPub.setId(wechatBlacklistPub.getWxid());
        //数据来源(0运营商共享 1官方采集-免费  2收费名单)
        wechatBlacklistPub.setSource(0);
        //增加到全网黑名单
        elasticsearchUtil.addData(wechatBlacklistPub, EsIndexName.UZAI_WECHAT_BLACKLIST_PUB, wechatBlacklistPub.getWxid());

        try {
            //延迟1秒
            Thread.sleep(1000);
        } catch (Exception e) {

        }
    }

    /**
     * 取消全网黑名单
     *
     * @param wechatBlacklistPrvIdDto
     * @return null
     * @author liuqi
     * @date 2021/8/13 11:38
     */
    public void cancelWechatBlacklistPub(WechatBlacklistPrvIdDto wechatBlacklistPrvIdDto) {
        if (StringUtils.isBlank(wechatBlacklistPrvIdDto.getId())) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id不能为空");
        }

        Map<String, Object> map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PRV, wechatBlacklistPrvIdDto.getId(), null);
        WechatBlacklistPrv wechatBlacklistPrv = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(map)), WechatBlacklistPrv.class);
        if (wechatBlacklistPrv == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该私有黑名单不存在");
        }

        Map<String, Object> pub_map = elasticsearchUtil.searchDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PUB, wechatBlacklistPrv.getWxid(), null);
        WechatBlacklistPub wechatBlacklistPub = JSONObject.parseObject(Tools.getStrEmpty(JSONObject.toJSONString(pub_map)), WechatBlacklistPub.class);
        if (wechatBlacklistPub == null) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该微信id不在全网黑名单里");
        }

        //判断是不是该运营商共享的全网黑名单
        if (wechatBlacklistPub.getMerId().longValue() != wechatBlacklistPrvIdDto.getMerId().longValue()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "该微信id是其他运营商共享到全网黑名单");
        }

        elasticsearchUtil.deleteDataById(EsIndexName.UZAI_WECHAT_BLACKLIST_PUB, wechatBlacklistPrv.getWxid());

        try {
            //延迟1秒
            Thread.sleep(1000);
        } catch (Exception e) {

        }
    }
}
